<template>
  <el-date-picker
    v-model="dateVaule"
    :type="type"
    :format="format"
    :value-format="valueFormat"
    :placeholder="placeholder"
    @change="onChange"
  />
</template>

<script>
import dayjs from 'dayjs'
export default {
  name: 'WiseDate',
  props: {
    value: {
      type: [String, Date, Number]
    },
    type: {
      type: String,
      default: 'date'
    },
    format: {
      type: String
    },
    valueFormat: {
      type: String
    },
    clearable: {
      type: Boolean,
      default: true
    },
    placeholder: {
      type: String,
      default: '选择日期'
    }
  },
  data() {
    return {
      dateVaule: null
    }
  },
  watch: {
    value(val) {
      if (val) {
        this.dateVaule = dayjs(val)
      } else {
        this.dateVaule = null
      }
    }
  },
  created() {
    if (this.value) {
      this.dateVaule = dayjs(this.value)
    } else {
      this.dateVaule = null
    }
  },
  methods: {
    onChange(value) {
      
      this.$emit('input', value?dayjs(value).valueOf():'')
    }
  }
}
</script>

<style scoped>

</style>
